/*
 * Synaptics TCM touchscreen driver
 *
 * Copyright (C) 2017-2018 Synaptics Incorporated. All rights reserved.
 *
 * Copyright (C) 2017-2018 Scott Lin <scott.lin@tw.synaptics.com>
 * Copyright (C) 2018-2019 Ian Su <ian.su@tw.synaptics.com>
 * Copyright (C) 2018-2019 Joey Zhou <joey.zhou@synaptics.com>
 * Copyright (C) 2018-2019 Yuehao Qiu <yuehao.qiu@synaptics.com>
 * Copyright (C) 2018-2019 Aaron Chen <aaron.chen@tw.synaptics.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS
 * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
 * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS.
 * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED
 * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES
 * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS'
 * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S.
 * DOLLARS.
 */

#ifndef _SYNAPTICS_TCM_TESTING_H_
#define _SYNAPTICS_TCM_TESTING_H_


/* Configurations for TRX TRX Short Test */
#define MAX_PINS (64)
#define CFG_IMAGE_TXES_OFFSET (2000)
#define CFG_IMAGE_TXES_LENGTH (576)
#define CFG_IMAGE_RXES_OFFSET (1728)
#define CFG_IMAGE_RXES_LENGTH (272)
#define CFG_NUM_TXGUARD_OFFSET (0)
#define CFG_NUM_TXGUARD_LENGTH (0)
#define CFG_NUM_RXGUARD_OFFSET (0)
#define CFG_NUM_RXGUARD_LENGTH (0)
#define CFG_TX_GUARD_PINS_OFFSET (0)
#define CFG_TX_GUARD_PINS_LENGTH (0)
#define CFG_RX_GUARD_PINS_OFFSET (0)
#define CFG_RX_GUARD_PINS_LENGTH (0)
#define CFG_IMAGE_CBCS_OFFSET (1392)
#define CFG_IMAGE_CBCS_LENGTH (272)
#define CFG_REF_LO_TRANS_CAP_OFFSET (2752)
#define CFG_REF_LO_TRANS_CAP_LENGTH (16)
#define CFG_REF_LO_XMTR_PL_OFFSET (4144)
#define CFG_REF_LO_XMTR_PL_LENGTH (16)
#define CFG_REF_HI_TRANS_CAP_OFFSET (2736)
#define CFG_REF_HI_TRANS_CAP_LENGTH (16)
#define CFG_REF_HI_XMTR_PL_OFFSET (4128)
#define CFG_REF_HI_XMTR_PL_LENGTH (16)
#define CFG_REF_GAIN_CTRL_OFFSET (0)
#define CFG_REF_GAIN_CTRL_LENGTH (0)


#define BUF_SIZE		(PAGE_SIZE * 2)
#define LOG_BUF_SIZE		256
#define MAX_LOG_FILE_SIZE	(10 * 1024 * 1024) /* 10 M byte */
#define MAX_LOG_FILE_COUNT	4
#define FILE_STR_LEN		(128)
#define TIME_STR_LEN		(64)
#define PRD_BLOCK_MAX		(20)

#define NOISE_TEST_CNT		(1)

enum {
	TIME_INFO_SKIP,
	TIME_INFO_WRITE,
};

/* Limit for Device ID Comparison Test */
static const char *device_id_limit = "3618";

/* Limit for Config ID Comparison Test */
static const char config_id_limit[16] = {
	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x47
};

/* Limit for Noise Test */
static const unsigned short noise_limits[36][17] = {
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
	{20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
};

/* Limit for Full Raw Test */
static const unsigned short pt5_full_raw_hi_limits[36][17] = {
	{ 850,  978,  991, 1001, 1008, 1020, 1023,  915, 9999, 1093, 1159, 1165, 1184, 1194, 1174, 1149, 1258},
	{ 960, 1023, 1025, 1034, 1038, 1050, 1061, 1068, 1035, 1118, 1139, 1158, 1183, 1196, 1178, 1168, 1128},
	{ 991, 1030, 1030, 1038, 1041, 1054, 1065, 1081, 1108, 1118, 1136, 1158, 1184, 1198, 1189, 1159, 1121},
	{ 994, 1031, 1030, 1039, 1043, 1055, 1065, 1084, 1115, 1119, 1138, 1159, 1196, 1199, 1180, 1160, 1116},
	{ 993, 1030, 1029, 1038, 1041, 1054, 1065, 1084, 1116, 1119, 1138, 1160, 1186, 1211, 1181, 1159, 1113},
	{ 993, 1029, 1029, 1036, 1041, 1054, 1065, 1084, 1116, 1119, 1149, 1161, 1188, 1201, 1183, 1160, 1110},
	{ 993, 1029, 1028, 1036, 1041, 1055, 1065, 1084, 1118, 1120, 1140, 1173, 1189, 1204, 1184, 1161, 1109},
	{ 993, 1029, 1029, 1038, 1041, 1055, 1066, 1085, 1129, 1121, 1141, 1164, 1191, 1205, 1185, 1163, 1108},
	{ 994, 1030, 1030, 1039, 1044, 1058, 1069, 1088, 1121, 1135, 1144, 1168, 1195, 1209, 1189, 1165, 1109},
	{ 996, 1033, 1031, 1040, 1045, 1059, 1070, 1100, 1124, 1128, 1148, 1170, 1198, 1213, 1191, 1168, 1110},
	{ 999, 1035, 1035, 1044, 1049, 1073, 1074, 1094, 1128, 1131, 1151, 1174, 1203, 1216, 1196, 1171, 1113},
	{1003, 1039, 1038, 1048, 1053, 1066, 1089, 1098, 1131, 1135, 1156, 1179, 1206, 1221, 1200, 1175, 1116},
	{1008, 1043, 1043, 1061, 1056, 1071, 1083, 1103, 1135, 1140, 1161, 1184, 1211, 1226, 1205, 1180, 1120},
	{1013, 1049, 1048, 1058, 1073, 1076, 1089, 1109, 1141, 1146, 1168, 1190, 1218, 1233, 1211, 1186, 1125},
	{1019, 1065, 1054, 1064, 1069, 1083, 1095, 1115, 1148, 1153, 1174, 1196, 1224, 1239, 1218, 1193, 1131},
	{1028, 1061, 1071, 1071, 1076, 1090, 1103, 1123, 1155, 1161, 1181, 1205, 1233, 1248, 1225, 1200, 1139},
	{1046, 1070, 1069, 1079, 1084, 1099, 1111, 1131, 1163, 1169, 1190, 1213, 1240, 1255, 1234, 1209, 1146},
	{1045, 1079, 1078, 1088, 1094, 1108, 1120, 1140, 1171, 1179, 1199, 1221, 1249, 1264, 1243, 1218, 1155},
	{1055, 1090, 1089, 1098, 1104, 1118, 1130, 1150, 1181, 1189, 1209, 1231, 1259, 1274, 1251, 1228, 1174},
	{1066, 1100, 1099, 1108, 1114, 1129, 1140, 1160, 1191, 1199, 1219, 1241, 1269, 1284, 1271, 1236, 1173},
	{1079, 1113, 1111, 1120, 1126, 1140, 1153, 1173, 1203, 1210, 1230, 1253, 1279, 1295, 1271, 1259, 1184},
	{1094, 1126, 1125, 1134, 1139, 1154, 1166, 1185, 1215, 1223, 1243, 1265, 1291, 1318, 1284, 1260, 1196},
	{1108, 1140, 1139, 1148, 1154, 1168, 1180, 1199, 1229, 1236, 1256, 1278, 1314, 1320, 1296, 1273, 1209},
	{1124, 1156, 1154, 1163, 1168, 1183, 1194, 1213, 1243, 1250, 1270, 1300, 1315, 1333, 1309, 1286, 1221},
	{1139, 1170, 1169, 1178, 1183, 1196, 1208, 1226, 1255, 1264, 1293, 1303, 1328, 1344, 1320, 1299, 1234},
	{1156, 1188, 1185, 1194, 1199, 1213, 1224, 1243, 1270, 1289, 1296, 1316, 1340, 1358, 1334, 1313, 1249},
	{1174, 1205, 1201, 1210, 1215, 1229, 1240, 1258, 1295, 1293, 1310, 1329, 1353, 1370, 1348, 1326, 1263},
	{1193, 1223, 1219, 1228, 1231, 1245, 1256, 1284, 1299, 1306, 1325, 1343, 1365, 1383, 1360, 1341, 1278},
	{1211, 1241, 1238, 1245, 1249, 1273, 1273, 1289, 1314, 1321, 1339, 1356, 1378, 1395, 1374, 1356, 1293},
	{1230, 1260, 1255, 1263, 1266, 1279, 1300, 1305, 1330, 1336, 1353, 1370, 1390, 1409, 1388, 1371, 1308},
	{1250, 1279, 1275, 1293, 1285, 1298, 1308, 1323, 1346, 1353, 1368, 1384, 1403, 1421, 1403, 1388, 1325},
	{1271, 1299, 1294, 1300, 1314, 1315, 1324, 1339, 1361, 1368, 1383, 1396, 1415, 1435, 1416, 1403, 1343},
	{1291, 1330, 1314, 1319, 1323, 1333, 1341, 1355, 1376, 1383, 1396, 1410, 1426, 1446, 1430, 1420, 1361},
	{1313, 1340, 1344, 1339, 1341, 1351, 1359, 1373, 1393, 1398, 1410, 1423, 1438, 1460, 1446, 1439, 1389},
	{1331, 1364, 1358, 1361, 1364, 1374, 1381, 1393, 1411, 1416, 1428, 1439, 1453, 1476, 1466, 1471, 1468},
	{1134, 1355, 1370, 1376, 1379, 1388, 1394, 1405, 1421, 1424, 1433, 1439, 1449, 1473, 1470, 1469, 1223},
};

static const unsigned short pt5_full_raw_lo_limits[36][17] = {
	{510, 587, 595, 601, 605, 612, 614, 549,   0, 656, 695, 699, 710, 716, 704, 689, 755},
	{576, 614, 615, 620, 623, 630, 637, 641, 621, 671, 683, 695, 710, 718, 707, 701, 677},
	{595, 618, 618, 623, 625, 632, 639, 649, 665, 671, 682, 695, 710, 719, 713, 695, 673},
	{596, 619, 618, 623, 626, 633, 639, 650, 669, 671, 683, 695, 718, 719, 708, 696, 670},
	{596, 618, 617, 623, 625, 632, 639, 650, 670, 671, 683, 696, 712, 727, 709, 695, 668},
	{596, 617, 617, 622, 625, 632, 639, 650, 670, 671, 689, 697, 713, 721, 710, 696, 666},
	{596, 617, 617, 622, 625, 633, 639, 650, 671, 672, 684, 704, 713, 722, 710, 697, 665},
	{596, 617, 617, 623, 625, 633, 640, 651, 677, 673, 685, 698, 715, 723, 711, 698, 665},
	{596, 618, 618, 623, 626, 635, 641, 653, 673, 681, 686, 701, 717, 725, 713, 699, 665},
	{598, 620, 619, 624, 627, 635, 642, 660, 674, 677, 689, 702, 719, 728, 715, 701, 666},
	{599, 621, 621, 626, 629, 644, 644, 656, 677, 679, 691, 704, 722, 730, 718, 703, 668},
	{602, 623, 623, 629, 632, 640, 653, 659, 679, 681, 694, 707, 724, 733, 720, 705, 670},
	{605, 626, 626, 637, 634, 643, 650, 662, 681, 684, 697, 710, 727, 736, 723, 708, 672},
	{608, 629, 629, 635, 644, 646, 653, 665, 685, 688, 701, 714, 731, 740, 727, 712, 675},
	{611, 639, 632, 638, 641, 650, 657, 669, 689, 692, 704, 718, 734, 743, 731, 716, 679},
	{617, 637, 643, 643, 646, 654, 662, 674, 693, 697, 709, 723, 740, 749, 735, 720, 683},
	{628, 642, 641, 647, 650, 659, 667, 679, 698, 701, 714, 728, 744, 753, 740, 725, 688},
	{627, 647, 647, 653, 656, 665, 672, 684, 703, 707, 719, 733, 749, 758, 746, 731, 693},
	{633, 654, 653, 659, 662, 671, 678, 690, 709, 713, 725, 739, 755, 764, 751, 737, 704},
	{640, 660, 659, 665, 668, 677, 684, 696, 715, 719, 731, 745, 761, 770, 763, 742, 704},
	{647, 668, 667, 672, 676, 684, 692, 704, 722, 726, 738, 752, 767, 777, 763, 755, 710},
	{656, 676, 675, 680, 683, 692, 700, 711, 729, 734, 746, 759, 775, 791, 770, 756, 718},
	{665, 684, 683, 689, 692, 701, 708, 719, 737, 742, 754, 767, 788, 792, 778, 764, 725},
	{674, 694, 692, 698, 701, 710, 716, 728, 746, 750, 762, 780, 789, 800, 785, 772, 733},
	{683, 702, 701, 707, 710, 718, 725, 736, 753, 758, 776, 782, 797, 806, 792, 779, 740},
	{694, 713, 711, 716, 719, 728, 734, 746, 762, 773, 778, 790, 804, 815, 800, 788, 749},
	{704, 723, 721, 726, 729, 737, 744, 755, 777, 776, 786, 797, 812, 822, 809, 796, 758},
	{716, 734, 731, 737, 739, 747, 754, 770, 779, 784, 795, 806, 819, 830, 816, 805, 767},
	{727, 745, 743, 747, 749, 764, 764, 773, 788, 793, 803, 814, 827, 837, 824, 814, 776},
	{738, 756, 753, 758, 760, 767, 780, 783, 798, 802, 812, 822, 834, 845, 833, 823, 785},
	{750, 767, 765, 776, 771, 779, 785, 794, 808, 812, 821, 830, 842, 853, 842, 833, 795},
	{763, 779, 776, 780, 788, 789, 794, 803, 817, 821, 830, 838, 849, 861, 850, 842, 806},
	{775, 798, 788, 791, 794, 800, 805, 813, 826, 830, 838, 846, 856, 868, 858, 852, 817},
	{788, 804, 806, 803, 805, 811, 815, 824, 836, 839, 846, 854, 863, 876, 868, 863, 833},
	{799, 818, 815, 817, 818, 824, 829, 836, 847, 850, 857, 863, 872, 886, 880, 883, 881},
	{680, 813, 822, 826, 827, 833, 836, 843, 853, 854, 860, 863, 869, 884, 882, 881, 734},
};

/* Limit for Abs Raw Test */
static const unsigned int hybrid_abs_rx_lo_limits[17] = {
	40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000
};

static const unsigned int hybrid_abs_rx_hi_limits[17] = {
	70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000, 70000
};

static const unsigned int hybrid_abs_tx_lo_limits[36] = {
	10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000
};

static const unsigned int hybrid_abs_tx_hi_limits[36] = {
	40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000
};

static const unsigned char reset_open_limit = 0x13;

/* Limit for High Resistance Test */
static const short pt8_high_resistance_rxroe_limit = 450;
static const short pt8_high_resistance_txroe_limit = 450;
static const short pt8_high_resistance_tixwl_limit = -400;

static const unsigned short discrete_ex_trx_short_upper_limit = 2000;
static const unsigned short discrete_ex_trx_short_lower_limit= 200;

static const unsigned char trx_ground_limits[16] = {
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};


#endif
